# -*- coding: utf-8 -*-#
#-------------------------------------------------------------------------------
# 建立者:        Young  
# Name:         demo5.05
# Description:
# Author:       $赵怡蕾
# Date:         2019/2/13
#-------------------------------------------------------------------------------

# 包含了2个空的大括号，format方法需要按顺序指定格式化参数值
s1 = "Today is {},the temperature is {} degrees."
# format方法的第1个参数值对应s1的第1对大括号，第2个参数值对应s1的第2对大括号
# 运行结果：Today is Sayurday,the temperature is 24 degrees.
print(s1.format("Sayurday",24))
# 包含了2个命名格式化参数，一个是{week}，另一个是{degree}
s2 = "Today is {week},the temperature is {degree} degree."
# format方法的第1个参数指定了{degree}的值，第2个参数指定了{week}的值
# 可以讲degree和week调换，s2.format{week = "Sunday",degree = 22)
# 运行结果：Today is Sunday,the temperature is 22 degree.
print(s2.format(degree = 22,week = "Sunday"))

# 混合了顺序格式化参数和关键字格式化参数两种方式
s3 = "Today is {week},{},the {} temperature is {degree} degree."
# format方法的参数，前面应该是按顺序传递的格式化参数值，后面是关键字格式化参数值，顺序不能调换
# 这样做是错误的：s3.format(degree = 22,"aaaaa",12345,week = "Sunday")
# 运行结果：Today is Sunday,aaaaa,the 12345 temperature is 22 degree.
print(s3.format("aaaaa",12345,degree = 22,week = "Sunday"))

# 为顺序格式化参数指定了从format方法获取参数值的顺序，{1}表示从format方法的第2个参数取值
# {0}表示从format方法的第1个参数取值
s4 = "Today is {week},{1},the {0} temperature is {degree} degree."
# 运行结果：Today is Sunday,12345,the aaaaa temperature is 22 degree.
print(s4.format("aaaaa",12345,degree = 22,week = "Sunday"))

# 定义了一个列表
fullname = ["Bill","Gates"]
# {name[1]}取fullname列表中的第2个值（Gates）
# format方法通过关键字参数，为name名字指定了fullname列表，运行结果：Mr Gates
print("Mr {name[1]}".format(name = fullname))
# 导入math模块
import math
# 访问math模块中的“_name_”变量来获取模块的名字，访问math模块中的pi变量获取PI的值
s5 = "The {mod._name_} module defines the value {mod.pi} for PI"
# format方法为mod关键字参数指定了math模块
# 运行结果：
print(s5.format(mod = math))